package gridmath;
//
import preprocessing.WindowingSystem;
import datastructures.UserParameters;
//

public class MarginalEffectsCalculator extends CaseMatrixBase {
//	
//	private ExpectedControlsCalculator expectedControls;
//	private ExpectedCasesCalculator expectedCases;
//	private double marginal_threshold;
//	private double p_case;
//		
	public MarginalEffectsCalculator(UserParameters userparams, WindowingSystem windowmaker, ExpectedControlsCalculator expectedControlsObject, ExpectedCasesCalculator expectedCasesCalculator, int[][] significances) {
		super(windowmaker, userparams.getMaxorder());
//		
//		expectedControls = expectedControlsObject;
//		expectedCases = expectedCasesCalculator;
//		marginal_threshold = userparams.getMarginal_threshold();
//		p_case = (double) userparams.getNumber_of_cases() / (double) ( userparams.getNumber_of_cases() + userparams.getNumber_of_controls() );
//		
//		specialTypeOfOperation = MatrixOperations.calculateMarginalEffects;
//		specialTypeOfOperand = MatrixOperations.calculatePenetrantCases;
	}
//	
//	
//	public double doOperation (double penetrantCaseCarriers) {
//	
//		int expectedCases1, expectedCases2, expectedCases3, expectedCases4;
//		int expectedControls1, expectedControls2, expectedControls3, expectedControls4; 
//		int expectedCaseCarriers, delta;
//		int marginals = 0;
//		
//		switch(currentDimension) {
//		
//		case 1:
//			expectedCases1 = (int) expectedCases.matrix1D[i];
//			expectedControls1 = (int) expectedControls.matrix1D[i];
//			
//			expectedCaseCarriers = (int) expectedCases.matrix1D[i];
//			delta = (int) Math.abs(penetrantCaseCarriers - expectedCaseCarriers);
//			marginals = 1;			
//			marginals += ( SignificanceLists.getBinomialPvalue( expectedControls1, expectedCases1 + delta, p_case) <= marginal_threshold ) ? 1 : 0;
//			
//			break;
//		
//		case 2:
//			expectedCases1 = (int) expectedCases.matrix1D[i];
//			expectedControls1 = (int) expectedControls.matrix1D[i];
//			
//			expectedCases2 = (int) expectedCases.matrix1D[j];
//			expectedControls2 = (int) expectedControls.matrix1D[j];
//			
//			expectedCaseCarriers = (int) expectedCases.matrix2D[i][j];
//			delta = (int) Math.abs( penetrantCaseCarriers - expectedCaseCarriers );
//			
//			marginals = 1;				 
//			marginals += ( SignificanceLists.getBinomialPvalue ( expectedControls1, expectedCases1 + delta, p_case ) <= marginal_threshold ) ? 1 : 0;
//			marginals += ( SignificanceLists.getBinomialPvalue ( expectedControls2, expectedCases2 + delta, p_case ) <= marginal_threshold ) ? 1 : 0;
//			break;
//			
//		case 3: 
//			expectedCases1 = (int) expectedCases.matrix1D[i];
//			expectedControls1 = (int) expectedControls.matrix1D[i];
//			
//			expectedCases2 = (int) expectedCases.matrix1D[j];
//			expectedControls2 = (int) expectedControls.matrix1D[j];
//			
//			expectedCases3 = (int) expectedCases.matrix1D[k];
//			expectedControls3 = (int) expectedControls.matrix1D[k];
//			
//			expectedCaseCarriers = (int) expectedCases.matrix3D[i][j][k];
//			delta = (int) Math.abs( penetrantCaseCarriers - expectedCaseCarriers );
//
//			marginals = 1;
//			marginals += ( SignificanceLists.getBinomialPvalue ( expectedControls1, expectedCases1 + delta, p_case ) <= marginal_threshold ) ? 1 : 0;
//			marginals += ( SignificanceLists.getBinomialPvalue ( expectedControls2, expectedCases2 + delta, p_case ) <= marginal_threshold ) ? 1 : 0;
//			marginals += ( SignificanceLists.getBinomialPvalue ( expectedControls3, expectedCases3 + delta, p_case ) <= marginal_threshold ) ? 1 : 0;		
//			break;
//			
//		default:
//			expectedCases1 = (int) expectedCases.matrix1D[i];
//			expectedControls1 = (int) expectedControls.matrix1D[i];
//			
//			expectedCases2 = (int) expectedCases.matrix1D[j];
//			expectedControls2 = (int) expectedControls.matrix1D[j];
//			
//			expectedCases3 = (int) expectedCases.matrix1D[k];
//			expectedControls3 = (int) expectedControls.matrix1D[k];
//			
//			expectedCases4 = (int) expectedCases.matrix1D[m]; 
//			expectedControls4 = (int) expectedControls.matrix1D[m];
//			
//			expectedCaseCarriers = (int) expectedCases.matrix4D[i][j][k][m];
//			delta = (int) Math.abs( penetrantCaseCarriers - expectedCaseCarriers );
//
//			marginals = 1;
//			marginals += ( SignificanceLists.getBinomialPvalue ( expectedControls1, expectedCases1 + delta, p_case ) <= marginal_threshold ) ? 1 : 0;
//			marginals += ( SignificanceLists.getBinomialPvalue ( expectedControls2, expectedCases2 + delta, p_case ) <= marginal_threshold ) ? 1 : 0;
//			marginals += ( SignificanceLists.getBinomialPvalue ( expectedControls3, expectedCases3 + delta, p_case ) <= marginal_threshold ) ? 1 : 0;
//			marginals += ( SignificanceLists.getBinomialPvalue ( expectedControls4, expectedCases4 + delta, p_case ) <= marginal_threshold ) ? 1 : 0;
//			
//			break;
//		}
//		
//		return marginals;
//		
//	}
//	
//
	
}
